]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
cleanup: Use g_clear_handle_id() for g_source_remove()
authorRobert Mader <robert.mader@posteo.de>
Fri, 22 Nov 2019 00:42:14 +0000 (01:42 +0100)
committerRobert Mader <robert.mader@posteo.de>
Fri, 22 Nov 2019 00:45:25 +0000 (01:45 +0100)
It makes sure we do not forget to zero the id and lets us avoid
zero checks before. We use it for all new code, lets clean up the
existing code base.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/845

src/calendar-server/calendar-sources.c
src/calendar-server/gnome-shell-calendar-server.c
src/hotplug-sniffer/hotplug-sniffer.c
src/hotplug-sniffer/shell-mime-sniffer.c
src/shell-app-usage.c
src/shell-perf-helper.c
src/shell-perf-log.c
src/shell-recorder-src.c
src/shell-recorder.c
src/st/st-scroll-bar.c

index 7e4c7f52e1a048d3aea1928ce34be7c2c30a79f4..bdc14542191bc0dd4dfaa2a185ae4f046f640b37 100644 (file)
@@ -242,11 +242,7 @@ calendar_sources_finalize_source_data (CalendarSources    *sources,
       g_hash_table_destroy (source_data->clients);
       source_data->clients = NULL;
 
-      if (source_data->timeout_id != 0)
-        {
-          g_source_remove (source_data->timeout_id);
-          source_data->timeout_id = 0;
-        }
+      g_clear_handle_id (&source_data->timeout_id, g_source_remove);
 
       source_data->loaded = FALSE;
     }
@@ -374,11 +370,7 @@ backend_died_cb (EClient *client, CalendarSourceData *source_data)
   g_warning ("The calendar backend for '%s' has crashed.", display_name);
   g_hash_table_remove (source_data->clients, source);
 
-  if (source_data->timeout_id != 0)
-    {
-      g_source_remove (source_data->timeout_id);
-      source_data->timeout_id = 0;
-    }
+  g_clear_handle_id (&source_data->timeout_id, g_source_remove);
 
   source_data->timeout_id = g_timeout_add_seconds (2, backend_restart,
                                                   source_data);
index d04f0019cb7355e44932907189aa2c44884754df..25cb694db339b752508ce4f8c638fe598fe94de2 100644 (file)
@@ -792,8 +792,7 @@ app_free (App *app)
   g_clear_signal_handler (&app->sources_signal_id, app->sources);
   g_object_unref (app->sources);
 
-  if (app->changed_timeout_id != 0)
-    g_source_remove (app->changed_timeout_id);
+  g_clear_handle_id (&app->changed_timeout_id, g_source_remove);
 
   g_free (app);
 }
index b8d7fa0ea8e28b4b1aa34f36c0d72370a174229f..fd087fd738b4fe45d64d22be20cfe87fd7566b9b 100644 (file)
@@ -60,11 +60,7 @@ ensure_autoquit_off (void)
   if (g_getenv ("HOTPLUG_SNIFFER_PERSIST") != NULL)
     return;
 
-  if (autoquit_id != 0)
-    {
-      g_source_remove (autoquit_id);
-      autoquit_id = 0;
-    }
+  g_clear_handle_id (&autoquit_id, g_source_remove);
 }
 
 static void
index cf53579a09af5027c9e8043858db33cf5a797cc7..6c56ecbaf57711452cc231e565797a72dde1dddf 100644 (file)
@@ -483,11 +483,7 @@ shell_mime_sniffer_dispose (GObject *object)
   g_clear_object (&self->priv->cancellable);
   g_clear_object (&self->priv->task);
 
-  if (self->priv->watchdog_id != 0)
-    {
-      g_source_remove (self->priv->watchdog_id);
-      self->priv->watchdog_id = 0;
-    }
+  g_clear_handle_id (&self->priv->watchdog_id, g_source_remove);
 
   G_OBJECT_CLASS (shell_mime_sniffer_parent_class)->dispose (object);
 }
index b8c3e75674767866bdfa81a12c8679aafffdd207..0dfb2099382e6ef02528612342d92d18ac956630 100644 (file)
@@ -328,8 +328,7 @@ shell_app_usage_finalize (GObject *object)
 {
   ShellAppUsage *self = SHELL_APP_USAGE (object);
 
-  if (self->save_id > 0)
-    g_source_remove (self->save_id);
+  g_clear_handle_id (&self->save_id, g_source_remove);
 
   g_object_unref (self->privacy_settings);
 
@@ -743,11 +742,7 @@ update_enable_monitoring (ShellAppUsage *self)
       if (self->watched_app)
         g_object_unref (self->watched_app);
       self->watched_app = NULL;
-      if (self->save_id)
-        {
-          g_source_remove (self->save_id);
-          self->save_id = 0;
-        }
+      g_clear_handle_id (&self->save_id, g_source_remove);
     }
 
   self->enable_monitoring = enable;
index e5eab208ba763bf82b55a189e9e9501cee08f817..f115dcbdc81dac7c7807b92c76c15ee927e31016 100644 (file)
@@ -84,8 +84,7 @@ on_timeout (gpointer data)
 static void
 establish_timeout (void)
 {
-  if (timeout_id != 0)
-    g_source_remove (timeout_id);
+  g_clear_handle_id (&timeout_id, g_source_remove);
 
   timeout_id = g_timeout_add (opt_idle_timeout * 1000, on_timeout, NULL);
   g_source_set_name_by_id (timeout_id, "[gnome-shell] on_timeout");
index cca3dc5b1908f0b4f789c575c3a94b6c89e9ca1f..e6fbb361539192018cc4ae2f2d25780f6135d81c 100644 (file)
@@ -218,8 +218,7 @@ shell_perf_log_set_enabled (ShellPerfLog *perf_log,
         }
       else
         {
-          g_source_remove (perf_log->statistics_timeout_id);
-          perf_log->statistics_timeout_id = 0;
+          g_clear_handle_id (&perf_log->statistics_timeout_id, g_source_remove);
         }
     }
 }
index d1a1640385bcc5a48df42b80e54625bceaec1c6b..617e3c0c40a73ab0e34ba95d901a955721067813 100644 (file)
@@ -241,8 +241,7 @@ shell_recorder_src_finalize (GObject *object)
 {
   ShellRecorderSrc *src = SHELL_RECORDER_SRC (object);
 
-  if (src->memory_used_update_idle)
-    g_source_remove (src->memory_used_update_idle);
+  g_clear_handle_id (&src->memory_used_update_idle, g_source_remove);
 
   shell_recorder_src_set_caps (src, NULL);
   g_queue_free_full (src->queue, (GDestroyNotify) gst_buffer_unref);
index cfafbaa0af705e09924a034584ecf89614dbc23b..43600ebbd05fbccbcd0720348d84b889aa824d4f 100644 (file)
@@ -220,8 +220,7 @@ shell_recorder_finalize (GObject  *object)
 {
   ShellRecorder *recorder = SHELL_RECORDER (object);
 
-  if (recorder->update_memory_used_timeout)
-    g_source_remove (recorder->update_memory_used_timeout);
+  g_clear_handle_id (&recorder->update_memory_used_timeout, g_source_remove);
 
   if (recorder->cursor_image)
     cairo_surface_destroy (recorder->cursor_image);
@@ -298,11 +297,7 @@ recorder_add_redraw_timeout (ShellRecorder *recorder)
 static void
 recorder_remove_redraw_timeout (ShellRecorder *recorder)
 {
-  if (recorder->redraw_timeout != 0)
-    {
-      g_source_remove (recorder->redraw_timeout);
-      recorder->redraw_timeout = 0;
-    }
+  g_clear_handle_id (&recorder->redraw_timeout, g_source_remove);
 }
 
 static void
@@ -608,11 +603,7 @@ recorder_add_update_pointer_timeout (ShellRecorder *recorder)
 static void
 recorder_remove_update_pointer_timeout (ShellRecorder *recorder)
 {
-  if (recorder->update_pointer_timeout)
-    {
-      g_source_remove (recorder->update_pointer_timeout);
-      recorder->update_pointer_timeout = 0;
-    }
+  g_clear_handle_id (&recorder->update_pointer_timeout, g_source_remove);
 }
 
 static void
@@ -648,11 +639,7 @@ recorder_disconnect_stage_callbacks (ShellRecorder *recorder)
    * us the events is close to free in any case.
    */
 
-  if (recorder->redraw_idle)
-    {
-      g_source_remove (recorder->redraw_idle);
-      recorder->redraw_idle = 0;
-    }
+  g_clear_handle_id (&recorder->redraw_idle, g_source_remove);
 }
 
 static void
index 3f118b0991ce00209b3088ca0bf055000459554c..c4551b5e903ed8fc57adad931061006e3f4d5347 100644 (file)
@@ -818,11 +818,7 @@ trough_button_release_event_cb (ClutterActor       *actor,
   if (event->button != 1)
     return FALSE;
 
-  if (priv->paging_source_id)
-    {
-      g_source_remove (priv->paging_source_id);
-      priv->paging_source_id = 0;
-    }
+  g_clear_handle_id (&priv->paging_source_id, g_source_remove);
 
   return TRUE;
 }
@@ -836,8 +832,7 @@ trough_leave_event_cb (ClutterActor *actor,
 
   if (priv->paging_source_id)
     {
-      g_source_remove (priv->paging_source_id);
-      priv->paging_source_id = 0;
+      g_clear_handle_id (&priv->paging_source_id, g_source_remove);
       return TRUE;
     }